package com.solidsnake.scala.service

import com.solidsnake.scala.http.HttpHandlerField
import java.net.URLEncoder

/**
 * Created with IntelliJ IDEA.
 * User: solidsnake
 * Date: 13-11-22
 * Time: 下午2:29
 * To change this template use File | Settings | File Templates.
 */
class ClientParams {
  var cookie = ""
  var viewState = ""

  def loadCookie(requestHandler : Map[String, String], responseHandler : Map[String, String]) {
    this.cookie = requestHandler.getOrElse(HttpHandlerField.COOKIE, "")
    this.cookie += requestHandler.getOrElse(HttpHandlerField.SET_COOKIE, "")
  }

  def loadViewState(html : String) {
    val vsP = "<input[^>]*id=\"__VIEWSTATE\"[^>]*value=\"([^\"]*)\"[^>]*>".r
    val vsP(vs) = vsP.findFirstIn(html).getOrElse("")
    this.viewState = vs
  }

  def encodeViewState = URLEncoder encode this.viewState
}

